/*
 * @Descripttion:
 * @version:
 * @@Company: DCIT-SH
 * @Author: 王富银
 * @Date: 2024-08-11 13:01:16
 * @LastEditors: Sunny Chen
 * @LastEditTime: 2024-08-11 13:19:51
 */
function formatDate(date) {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  const hours = String(date.getHours()).padStart(2, "0");
  const minutes = String(date.getMinutes()).padStart(2, "0");
  const seconds = String(date.getSeconds()).padStart(2, "0");

  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

function getRandomDate(startDate, endDate) {
  // 将开始时间和结束时间转换为时间戳
  const startTimestamp = startDate.getTime();
  const endTimestamp = endDate.getTime();

  // 生成一个在开始时间和结束时间之间的随机时间戳
  const randomTimestamp =
    startTimestamp + Math.random() * (endTimestamp - startTimestamp);

  // 将随机时间戳转换为 Date 对象
  return new Date(randomTimestamp);
}
const start = new Date("2022-06-05T00:00:00");
const arr = [];
for (let i = 2; i <= 33; i++) {
  //id
  let id = "XH";
  if (i < 10) {
    id += "00" + i;
  } else if (i >= 10 && i < 99) {
    id += "0" + i;
  } else {
    id += i;
  }
  const obj = {};
  obj.id = id;
  obj.trajectorys = [];
  const objCoor = {};
  objCoor.coordinates = [];
  const date = formatDate(getRandomDate(start, new Date()));
  objCoor.date = date;
  let temp1 = date.split(" ")[0].split("-");
  let temp2 = date.split(" ")[1].split(":");
  objCoor.id = id + "-" + temp1[1] + temp1[2] + "-" + temp2[0] + temp2[1];
  obj.trajectorys.push(objCoor);
  arr.push(obj);
}
console.log(JSON.stringify(arr));
